package test_base

import (
	"fmt"
	"unsafe"
)

var _g int

/* 定义结构体 */
type Circle struct {
	radius float64
}

func Do() {
	fmt.Println("Hello, world!")
	fmt.Println("Hello, world!" + "丢")

	_g = 888990

	var v = fmt.Sprintf("Code=%d", 0)
	fmt.Println(v)

	var b, c string = "jfkj", "Df"
	fmt.Println(b)
	fmt.Println(c)

	var i32, i34 int64 = 1, 2
	fmt.Println(i32, i34)

	var a = "rerei"
	fmt.Println(a)

	var aa = 2
	fmt.Println(aa)

	var bb int
	fmt.Println(bb)

	var vv bool
	fmt.Println(vv)

	var ee error
	fmt.Println(ee)

	var i int
	var f float64
	var bBB bool
	var s string
	fmt.Printf("%v %v %v %q\n", i, f, bBB, s)

	v_name := "jinzhi"
	fmt.Println(v_name)

	vname1, vname2 := "su", "djfk"
	fmt.Println(vname1, vname2)

	vname1, vname2 = vname2, vname1
	fmt.Println(vname1, vname2)

	const (
		a2 = "abc"
		b2 = len(a2)
		c2 = unsafe.Sizeof(a2)
	)

	println(a2, b2, c2)

	const (
		a3 = 1 << iota
		b3 = 4 << iota
		c3
		d3
		e3
	)
	println(a3, b3, c3, d3, e3)

	const kk int = iota

	println(kk)

	var a5 int = 4
	var b5 int32
	var c5 float32
	var ptr5 *int

	/* 运算符实例 */
	fmt.Printf("第 1 行 - a 变量类型为 = %T\n", a5)
	fmt.Printf("第 2 行 - b 变量类型为 = %T\n", b5)
	fmt.Printf("第 3 行 - c 变量类型为 = %T\n", c5)
	fmt.Printf("第 3 行 - c 变量类型为 = %T\n", ptr5)

	ptr5 = &a5

	fmt.Printf("a 的值为  %d\n", a5)
	fmt.Printf("*ptr 为 %d\n", *ptr5)
	fmt.Printf("*ptr 为 %d\n", ptr5)

	if a5 < 3 {

	}

	var grade string = "B"
	var marks int = 90

	switch marks {
	case 90:
		grade = "A"
	case 80:
		grade = "B"
	case 50, 60, 70:
		grade = "C"
	default:
		grade = "D"
	}

	fmt.Printf("%s", grade)

	aaa := 0
	for aaa < 100 {
		aaa++
	}

	fmt.Printf("%d\n", aaa)

	fmt.Println(test("Fdf", "dser"))
	a7, b7 := 8, 9
	swap(&a7, &b7)
	fmt.Println(a7, b7)

	Root := func(num int) int {
		return num * 3
	}

	fmt.Println(Root(3))

	nextNum := getSeq()

	fmt.Println(nextNum())
	fmt.Println(nextNum())
	fmt.Println(nextNum())

	nextNum1 := getSeq()
	fmt.Println(nextNum1())

	var cccc Circle
	fmt.Println(cccc.radius)
	cccc.radius = 10
	fmt.Println(cccc.getArea())
	cccc.setRadius(11)
	setRadius3(&cccc, 12)
	fmt.Println(cccc.radius)

	var balance = [5]int{110, 11, 34, 34, 43}
	fmt.Println(balance)

	balance2 := [...]float32{23, 34, 43}
	fmt.Println(balance2)

	balance2[2] = 32
	fmt.Println(balance2)

	var n [10]int
	var iii, j int

	for iii = 0; iii < 10; iii++ {
		n[iii] = iii + 100
	}

	for j = 0; j < 10; j++ {
		fmt.Printf("e[%d] = %d \n", j, n[j])
	}

	balance4 := [5]float32{0: 3.0, 2: 0.2, 8}

	for i := 0; i < len(balance4); i++ {
		fmt.Printf("b [d%] = %f\n", i, balance4[i])

	}

	values := [][]int{}

	row1 := []int{1, 3, 4.0}
	row2 := []int{3, 4, 5}
	values = append(values, row1)
	values = append(values, row2)

	fmt.Println(values)
	fmt.Println(values[1])
	// fmt.Println(values[2]) //index out of range [2] with length 2

	afdf := [3][4]int{
		{0, 1, 2, 3},   /*  第一行索引为 0 */
		{4, 5, 6, 7},   /*  第二行索引为 1 */
		{8, 9, 10, 11}, /* 第三行索引为 2 */
	}

	fmt.Println(afdf)
}

func (c Circle) getArea() float64 {
	return 3.1415926 * c.radius * c.radius
}

func (c *Circle) setRadius(r float64) {
	c.radius = r
}

func setRadius3(c *Circle, r float64) {
	c.radius = r
}

func test(num, str string) string {
	var result string
	result = num + str
	return result
}

func swap(x, y *int) {
	*x, *y = *y, *x
}

func getSeq() func() int {
	i := 0
	return func() int {
		i++
		return i
	}

}
